#include "account.h"


std::string account::getName()
{
    return Name;
}

std::string account::getPeopleID()
{
    return PeopleID;
}

std::string account::getAccountID()
{
    return AccountID;
}

std::string account::getPassword()
{
    return Password;
}

int account::getBalance()
{
    return Balance;
}


void account::SetPassword(std::string new_password)
{
    Password=new_password;
}

void account::AddBalance(int money)
{
    Balance+=money;
}

void account::SubBalance(int money)
{
    Balance-=money;
}

int account::PswordTrue()
{
    PswordWrongNum=0;           //密码输入正确则重置错误次数
    return 0;
}

int account::PswordWrong()
{
    return ++PswordWrongNum;    //密码输入错误则错误次数+1
}

int account::getPswordWrongNum()
{
    return PswordWrongNum;
}

const std::vector<std::pair<int,std::string>>& account::getWithdrawRecords()
{
    return WithdrawRecords;
}

std::istream& operator>>(std::istream& is,account& zhanghu)
{
    is>>zhanghu.Name;
    is>>zhanghu.PeopleID;
    is>>zhanghu.AccountID;
    is>>zhanghu.Password;
    is>>zhanghu.PswordWrongNum;
    is>>zhanghu.Balance;
    zhanghu.DepositRecords.clear();
    zhanghu.WithdrawRecords.clear();        //先清空上一个用户的数据

    int n;
    is>>n;
    for (int i=0;i<n;i++)
    {
        int money;
        std::string time1,time="";
        is>>money;
        for (int i=0;i<5;i++)
        {
            if (i==0)
            {
                is>>time1;
                time+=time1;
            }
            else
            {
                is>>time1;
                time=time+" "+time1;
            }
        }
        std::pair<int,std::string> a{money,time};
        zhanghu.DepositRecords.push_back(a);
    }

    is>>n;
    for (int i=0;i<n;i++)
    {
        int money;
        std::string time1,time="";
        is>>money;
        for (int i=0;i<5;i++)
        {
            if (i==0)
            {
                is>>time1;
                time+=time1;
            }
            else
            {
                is>>time1;
                time=time+" "+time1;
            }
        }
        std::pair<int,std::string> a{money,time};
        zhanghu.WithdrawRecords.push_back(a);
    }
    return is;
}

std::ostream& operator<<(std::ostream& os,account& zhanghu)
{
    os<<zhanghu.Name<<std::endl;
    os<<zhanghu.PeopleID<<std::endl;
    os<<zhanghu.AccountID<<std::endl;
    os<<zhanghu.Password<<std::endl;
    os<<zhanghu.PswordWrongNum<<std::endl;
    os<<zhanghu.Balance<<std::endl;
    os<<std::endl;

    int n=zhanghu.DepositRecords.size();
    os<<n<<std::endl;
    for(int i=0;i<n;i++)
    {
        os<<zhanghu.DepositRecords[i].first<<" ";
        os<<zhanghu.DepositRecords[i].second<<std::endl;
    }
    os<<std::endl;

    n=zhanghu.WithdrawRecords.size();
    os<<n<<std::endl;
    for(int i=0;i<n;i++)
    {
        os<<zhanghu.WithdrawRecords[i].first<<" ";
        os<<zhanghu.WithdrawRecords[i].second<<std::endl;
    }
    return os;
}

void account::AddDeposit(int money,std::string time)
{
    DepositRecords.push_back(std::pair<int,std::string>(money,time));
}

void account::AddWithdraw(int money, std::string time)
{
    WithdrawRecords.push_back(std::pair<int,std::string>(money,time));
}
